# coding: utf-8
def write_example():
    '''
    file.write(str)将字符串写入文件，返回的是写入的字符长度。
    file.writelines(sequence)向文件写入一个序列字符串列表，如果需要换行则要自己加入每行的换行符。
    :return:
    '''
    with open("./test.txt", 'w') as f:
        f.write("line1\nline2\n")
        f.writelines("line3\nline4")


def read_example():
    with open("./test.txt", 'r') as f:
        # ex1 = f.read()
        # ex2 = f.readline()
        # ex3 = f.readlines()
        ex4 = f.read().splitlines()
        # print(ex1)
        # print(ex2)
        # print(ex3)
        print(ex4)


if __name__ == '__main__':
    # write_example()
    read_example()